package com.ebt.m.msgnote;

import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.widget.TextView;

import com.ebt.m.R;
import com.ebt.m.commons.buscomponent.listview.IView;
import com.ebt.m.utils.DateUtils;

import java.util.Date;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by allen on 2018/7/31 10:28.
 */
public class TypeMsgDateItemView extends IView {
    @BindView(R.id.tvDate)
    TextView tvDate;

    public TypeMsgDateItemView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        inflate(context, R.layout.msg_type_date, this);
    }

    public TypeMsgDateItemView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public TypeMsgDateItemView(Context context) {
        this(context, null);
        ButterKnife.bind(this);
    }

    @Override
    public void update(Object... args) {
        CharSequence date = (CharSequence) args[0];
        if (TextUtils.isEmpty(date)) {
            tvDate.setText("");
        } else {
            if (DateUtils.dateTime2String(new Date(), DateUtils.YYYY_MM_DD).equals(DateUtils.formatDate(date.toString(), DateUtils.YYYY_MM_DD))) {
                tvDate.setText("今天");
            } else {
                tvDate.setText(date);
            }
        }
    }
}
